/*
**  Copyright (c) 2014 Michael Liu(michael.liu.point@gmail.com).
**
**  Project: Gateway Unified Management Platform
**  File:      dpapi.c
**  Author:  Michael
**  Date:    06/27/2014
**
**  Purpose:
**     Data Path Management API implement.
*/

/* Include files. */

#include "cmapi.h"

/* Macro constant definitions. */

/* Type definitions. */

/* Local function declarations. */

/* Macro API definitions. */

/* Global variable declarations. */

e_ret sa_submod_operation(tcm_session * session, unsigned submod,
			  void *submod_req, int submod_req_size, void *submod_rsp, int submod_rsp_size)
{
	e_ret ret;
	int req_size;
	int rsp_size;
	void **tmp;
	tcm_req_body *req;
	tcm_rsp_body *rsp;
	tcm_sa_req_body *sa_req;
	tcm_sa_rsp_body *sa_rsp;

	req_size = sizeof(*req) + sizeof(*sa_req) + submod_req_size;
	req = malloc(req_size);
	if (req == NULL) {
		cmapi_error("malloc(%d) failed, err: %d,[%s]\n", req_size, errno, strerror(errno));
		return (eRET_NO_RESOURCE);
	}
	memset(req, 0, req_size);
	req->module = eCM_MODULE_SYS_ADMIN;
	req->req_body_len = sizeof(*sa_req) + submod_req_size;

	sa_req = (tcm_sa_req_body *) req->mod_req_body;
	sa_req->submod = submod;
	memcpy(sa_req->body, submod_req, submod_req_size);

	rsp = NULL;
	rsp_size = 0;
	tmp = (void *)&rsp;
	ret = cmapi_require(session, 1, req, req_size, tmp, &rsp_size);
	free(req);
	if (rsp != NULL) {
		if (rsp->rsp_body_len != 0) {
			sa_rsp = (tcm_sa_rsp_body *) rsp->mod_rsp_body;
			memcpy(submod_rsp, sa_rsp->body, submod_rsp_size);
		}

		if (rsp->ret != eRET_SUCCESS) {
			ret = rsp->ret;
		}
		free(rsp);
	}

	return (ret);

}

e_ret sa_sm_operation(tcm_session * session, tcm_sa_sm_req_body * sa_sm_req, tcm_sa_sm_rsp_body * sa_sm_rsp)
{
	return (sa_submod_operation(session, eSA_SUB_MOD_SYS_MGR,
				    sa_sm_req, sizeof(*sa_sm_req), sa_sm_rsp, sizeof(*sa_sm_rsp)));
}

e_ret sa_cm_operation(tcm_session * session, tcm_sa_cm_req_body * sa_cm_req, tcm_sa_cm_rsp_body * sa_cm_rsp)
{
	return (sa_submod_operation(session, eSA_SUB_MOD_CFG_MGR,
				    sa_cm_req, sizeof(*sa_cm_req), sa_cm_rsp, sizeof(*sa_cm_rsp)));
}

e_ret sa_fm_operation(tcm_session * session, tcm_sa_fm_req_body * sa_fm_req, tcm_sa_fm_rsp_body * sa_fm_rsp)
{
	return (sa_submod_operation(session, eSA_SUB_MOD_FW_MGR,
				    sa_fm_req, sizeof(*sa_fm_req), sa_fm_rsp, sizeof(*sa_fm_rsp)));
}

e_ret sa_lm_operation(tcm_session * session, tcm_sa_lm_req_body * sa_lm_req, tcm_sa_lm_rsp_body * sa_lm_rsp)
{
	return (sa_submod_operation(session, eSA_SUB_MOD_LOG_MGR,
				    sa_lm_req, sizeof(*sa_lm_req), sa_lm_rsp, sizeof(*sa_lm_rsp)));
}

e_ret sa_sm_verify_password(tcm_session * session, const char *password, unsigned char *ok)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_VERIFY_PASSWORD;
	strcpy(sa_sm_req.pswd.password, password);

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		*ok = eBOOL_FALSE;
		return (ret);
	}

	*ok = sa_sm_rsp.pswd.verify_ok;

	return (eRET_SUCCESS);

}

e_ret sa_sm_set_password(tcm_session * session, const char *password)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_SET_PASSWORD;
	strcpy(sa_sm_req.pswd.password, password);

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_sm_get_password(tcm_session * session, char *password)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_GET_PASSWORD;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}
	strcpy(password, sa_sm_rsp.pswd.password);

	return (eRET_SUCCESS);

}

e_ret sa_sm_get_qis(tcm_session * session, unsigned char *qis_done)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_GET_QIS;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		*qis_done = eBOOL_FALSE;
		return (ret);
	}

	*qis_done = sa_sm_rsp.qis.qis_done;

	return (eRET_SUCCESS);

}

e_ret sa_sm_set_qis(tcm_session * session, unsigned char qis_done)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_SET_QIS;
	sa_sm_req.qis.qis_done = qis_done;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_sm_get_language(tcm_session * session, unsigned char *lang)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_GET_LANGUAGE;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		*lang = eBOOL_FALSE;
		return (ret);
	}

	*lang = sa_sm_rsp.lang;

	return (eRET_SUCCESS);

}

e_ret sa_sm_set_language(tcm_session * session, unsigned char lang)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_SET_LANGUAGE;
	sa_sm_req.lang = lang;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_sm_get_uptime(tcm_session * session, struct date_time * datetime)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_GET_UPTIME;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	*datetime = sa_sm_rsp.uptime;

	return (eRET_SUCCESS);

}

e_ret sa_sm_get_datetime(tcm_session * session, struct date_time * datetime)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_GET_DATETIME;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	*datetime = sa_sm_rsp.datetime.datetime;

	return (eRET_SUCCESS);

}

e_ret sa_sm_set_datetime(tcm_session * session, struct date_time datetime)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_SET_DATETIME;
	sa_sm_req.datetime.datetime = datetime;
	sa_sm_req.datetime.use_ntp = eBOOL_FALSE;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_sm_get_ntp(tcm_session * session, char *net_server)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_GET_DATETIME;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	strcpy(net_server, sa_sm_rsp.datetime.ntp_server);

	return (eRET_SUCCESS);

}

e_ret sa_sm_set_ntp(tcm_session * session, const char *ntp_server)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_SET_DATETIME;
	strcpy(sa_sm_req.datetime.ntp_server, ntp_server);
	sa_sm_req.datetime.use_ntp = eBOOL_TRUE;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_sm_get_timezone(tcm_session * session, unsigned int *timezone)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_GET_TIMEZONE;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}
	*timezone = sa_sm_rsp.datetime.tz;

	return (eRET_SUCCESS);

}

e_ret sa_sm_set_timezone(tcm_session * session, unsigned int timezone)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_SET_TIMEZONE;
	sa_sm_req.datetime.tz = timezone;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_sm_get_power_save(tcm_session * session, unsigned char *power_save)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_GET_POWER_SAVE;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}
	*power_save = sa_sm_rsp.power_save;

	return (eRET_SUCCESS);

}

e_ret sa_sm_set_power_save(tcm_session * session, unsigned char power_save)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_SET_POWER_SAVE;
	sa_sm_req.power_save = power_save;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_sm_reboot(tcm_session * session)
{
	e_ret ret;
	tcm_sa_sm_req_body sa_sm_req;
	tcm_sa_sm_req_body sa_sm_rsp;

	memset(&sa_sm_req, 0, sizeof(sa_sm_req));
	memset(&sa_sm_rsp, 0, sizeof(sa_sm_rsp));

	sa_sm_req.opt = eSYS_MGR_OPT_REBOOT;

	ret = sa_sm_operation(session, &sa_sm_req, &sa_sm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_sm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_cm_dump_cfg(tcm_session * session, char *cfg_file)
{
	e_ret ret;
	tcm_sa_cm_req_body sa_cm_req;
	tcm_sa_cm_req_body sa_cm_rsp;

	memset(&sa_cm_req, 0, sizeof(sa_cm_req));
	memset(&sa_cm_rsp, 0, sizeof(sa_cm_rsp));

	sa_cm_req.opt = eCFG_MGR_OPT_DUMP_CFG;

	ret = sa_cm_operation(session, &sa_cm_req, &sa_cm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_cm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}
	strcpy(cfg_file, sa_cm_rsp.cfg_file);

	return (eRET_SUCCESS);

}

e_ret sa_cm_load_cfg(tcm_session * session, char *cfg_file)
{
	e_ret ret;
	tcm_sa_cm_req_body sa_cm_req;
	tcm_sa_cm_req_body sa_cm_rsp;

	memset(&sa_cm_req, 0, sizeof(sa_cm_req));
	memset(&sa_cm_rsp, 0, sizeof(sa_cm_rsp));

	sa_cm_req.opt = eCFG_MGR_OPT_LOAD_CFG;
	strcpy(sa_cm_req.cfg_file, cfg_file);

	ret = sa_cm_operation(session, &sa_cm_req, &sa_cm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_cm_load_cfg() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_cm_reset_cfg(tcm_session * session)
{
	e_ret ret;
	tcm_sa_cm_req_body sa_cm_req;
	tcm_sa_cm_req_body sa_cm_rsp;

	memset(&sa_cm_req, 0, sizeof(sa_cm_req));
	memset(&sa_cm_rsp, 0, sizeof(sa_cm_rsp));

	sa_cm_req.opt = eCFG_MGR_OPT_RESET_CFG;

	ret = sa_cm_operation(session, &sa_cm_req, &sa_cm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_cm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_fm_get_version(tcm_session * session, char *version)
{
	e_ret ret;
	tcm_sa_fm_req_body sa_fm_req;
	tcm_sa_fm_req_body sa_fm_rsp;

	memset(&sa_fm_req, 0, sizeof(sa_fm_req));
	memset(&sa_fm_rsp, 0, sizeof(sa_fm_rsp));

	sa_fm_req.opt = eFW_MGR_OPT_GET_VERSION;

	ret = sa_fm_operation(session, &sa_fm_req, &sa_fm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_fm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}
	strcpy(version, sa_fm_rsp.fm_info.version);

	return (eRET_SUCCESS);

}

e_ret sa_fm_local_upgrade(tcm_session * session, char *fw_name)
{
	e_ret ret;
	tcm_sa_fm_req_body sa_fm_req;
	tcm_sa_fm_req_body sa_fm_rsp;

	memset(&sa_fm_req, 0, sizeof(sa_fm_req));
	memset(&sa_fm_rsp, 0, sizeof(sa_fm_rsp));

	sa_fm_req.opt = eFW_MGR_OPT_DO_LOCAL_UPGRADE;
	strcpy(sa_fm_req.fw_file, fw_name);

	ret = sa_fm_operation(session, &sa_fm_req, &sa_fm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_fm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_fm_start_fota_check(tcm_session * session)
{
	e_ret ret;
	tcm_sa_fm_req_body sa_fm_req;
	tcm_sa_fm_req_body sa_fm_rsp;

	memset(&sa_fm_req, 0, sizeof(sa_fm_req));
	memset(&sa_fm_rsp, 0, sizeof(sa_fm_rsp));

	sa_fm_req.opt = eFW_MGR_OPT_START_FOTA_CHECK;

	ret = sa_fm_operation(session, &sa_fm_req, &sa_fm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_fm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_fm_query_fota_check(tcm_session * session, char *version)
{
	e_ret ret;
	tcm_sa_fm_req_body sa_fm_req;
	tcm_sa_fm_req_body sa_fm_rsp;

	memset(&sa_fm_req, 0, sizeof(sa_fm_req));
	memset(&sa_fm_rsp, 0, sizeof(sa_fm_rsp));

	sa_fm_req.opt = eFW_MGR_OPT_QUERY_FOTA_CHECK;

	ret = sa_fm_operation(session, &sa_fm_req, &sa_fm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_fm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}
	strcpy(version, sa_fm_rsp.fm_info.version);

	return (eRET_SUCCESS);

}

e_ret sa_fm_cancel_fota_check(tcm_session * session)
{
	e_ret ret;
	tcm_sa_fm_req_body sa_fm_req;
	tcm_sa_fm_req_body sa_fm_rsp;

	memset(&sa_fm_req, 0, sizeof(sa_fm_req));
	memset(&sa_fm_rsp, 0, sizeof(sa_fm_rsp));

	sa_fm_req.opt = eFW_MGR_OPT_CANCEL_FOTA_CHECK;

	ret = sa_fm_operation(session, &sa_fm_req, &sa_fm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_fm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_fm_start_fota_upgrade(tcm_session * session)
{
	e_ret ret;
	tcm_sa_fm_req_body sa_fm_req;
	tcm_sa_fm_req_body sa_fm_rsp;

	memset(&sa_fm_req, 0, sizeof(sa_fm_req));
	memset(&sa_fm_rsp, 0, sizeof(sa_fm_rsp));

	sa_fm_req.opt = eFW_MGR_OPT_START_FOTA_UPGRADE;

	ret = sa_fm_operation(session, &sa_fm_req, &sa_fm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_fm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_fm_query_fota_upgrade(tcm_session * session)
{
	e_ret ret;
	tcm_sa_fm_req_body sa_fm_req;
	tcm_sa_fm_req_body sa_fm_rsp;

	memset(&sa_fm_req, 0, sizeof(sa_fm_req));
	memset(&sa_fm_rsp, 0, sizeof(sa_fm_rsp));

	sa_fm_req.opt = eFW_MGR_OPT_QUERY_FOTA_UPGRADE;

	ret = sa_fm_operation(session, &sa_fm_req, &sa_fm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_fm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}

e_ret sa_fm_cancel_fota_upgrade(tcm_session * session)
{
	e_ret ret;
	tcm_sa_fm_req_body sa_fm_req;
	tcm_sa_fm_req_body sa_fm_rsp;

	memset(&sa_fm_req, 0, sizeof(sa_fm_req));
	memset(&sa_fm_rsp, 0, sizeof(sa_fm_rsp));

	sa_fm_req.opt = eFW_MGR_OPT_CANCEL_FOTA_UPGRADE;

	ret = sa_fm_operation(session, &sa_fm_req, &sa_fm_rsp);
	if (ret != eRET_SUCCESS) {
		cmapi_error("sa_fm_operation() failed, ret: %d.\n", ret);
		return (ret);
	}

	return (eRET_SUCCESS);

}
